# -*- coding: utf-8 -*-

#from django.contrib.auth.models import AbstractUser
from django.db import models
from django.contrib.auth import get_user_model
User = get_user_model()


LEVEL_CHOICE = ( 
    ("1", "1"),  
    ("2", "2"),
    ("3", "3"),
    ("4", "4"),
    ("5", "5"),   
)


class Group(models.Model):
    """
           分组信息
    """
    name = models.CharField(max_length=30, verbose_name="分组名")
    status = models.BooleanField("使能", default=True)
    
    class Meta:
        verbose_name = "分组信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class UserProfile(models.Model):
    """
           用户信息
    """
    username = models.CharField(max_length=30, verbose_name="用户名")
    status = models.BooleanField("使能", default=True)
    email = models.EmailField(max_length=100, verbose_name="邮箱")
    password = models.CharField(max_length=200, verbose_name="密码", default="pbkdf2_sha256$150000$bouffalo$0VLVZiG1MmVoRhMdvCxYzqFmF+TDSPE4QcqCbJa+cxg=")
    #birthday = models.DateField(verbose_name="出生日期", null=True, blank=True)
    #gender = models.CharField(max_length=6, choices=(("male", u"男"), ("female", "女")), default="male", verbose_name="性别")
    name = models.CharField(max_length=16, verbose_name="姓名", null=True, blank=True)
    company = models.CharField(max_length=100, verbose_name="公司", null=True, blank=True)
    phone = models.CharField(max_length=20, verbose_name="电话", null=True, blank=True)
    level = models.CharField("等级", max_length=10, choices=LEVEL_CHOICE, default="1")
    #user = models.OneToOneField(User, verbose_name="系统关联用户", related_name="auth", on_delete=models.CASCADE, null=True)
    date = models.DateTimeField("添加日期", auto_now_add=True, null=True, blank=True)
    group = models.ForeignKey(Group, on_delete=models.CASCADE, verbose_name="分组", blank=True, null=True)

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class UserToken(models.Model):
    """
    token
    """
    user = models.OneToOneField(UserProfile, on_delete=models.CASCADE, null=True)
    token = models.CharField(max_length=500)
    
    
    
    
